<?php
 class Area extends Smvc {
	 
	private $tabela ="AREA";	 
 		
	function __construct(){
		parent::__construct();
		if(!isset($_SESSION['login'])){$this->jump();}
		
		$this->gproj=new gproj;	
	}
	
function index(){ 
	
   $data['js']="area";
   
   $data['codigo']="";
   $data['nome']="";
   $data['acao']="salvar()";
	
	$this->view('area',$data,'site');	
}
	
function salvar(){ 

      $codigo=$this->gproj->autoincrement($this->tabela,"ARE_CODIGO");
      $nome=utf8_decode($_POST['nome']);

	  $campos ="ARE_CODIGO,ARE_NOME";
	  $valores = "$codigo,'$nome'";
		
	  $this->gproj->insert($this->tabela,$campos,$valores);
			  	  
}



function set_area(){
	

   $query=$this->sql->query("SELECT * FROM AREA");

 ?>
 <table class="listagem" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th>Area</th>
    <th width="51">Deletar</th>
  </tr>

<?php foreach($query as $row){	?>
	<tr>
    <td style="cursor:pointer" onclick="edit(<?=$row->ARE_CODIGO?>)"><?=$row->ARE_NOME;?></td>
    <td><img src="<?=SERVER?>_public/img/icons/del.png" style="cursor:pointer" onclick="deletar(<?=$row->ARE_CODIGO?>)"></td>
  </tr>
	
<?php  } ?>

</table>  
   
 <?  
   
}

function deletar(){ 

    $codigo=$_POST['codigo'];
	$valores = "ARE_CODIGO = $codigo";
	$this->gproj->delete($this->tabela,$valores);
}

function edit($codigo){ 

	 $query=$this->sql->query("SELECT * FROM AREA WHERE ARE_CODIGO =".$codigo."");
	 foreach($query as $row){ $data['nome']=$row->ARE_NOME;	}
	 
	 $data['js']="area";
	 
	 $data['acao']="atualizar(".$row->ARE_CODIGO.")";
	
	 $this->view('area',$data,'site');
	
}

function atualizar(){ 

	  $codigo=$_POST['codigo'];
	  $nome = utf8_decode($_POST['nome']);
	 
	 $campos ="ARE_NOME = '".$nome."'";
	 $valores = "ARE_CODIGO=".$codigo."";	
	 $this->gproj->update($this->tabela,$campos,$valores);	
	 
}
	
	
	
}